package com.owc;

import com.owc.common.configuration.OssConfig;
import com.owc.common.configuration.OwcConfig;
import com.owc.common.oss.OssUtils;
import com.owc.common.redis.RedisUtil;
import com.owc.domain.entity.SystemConfig;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.annotation.Order;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.data.web.SortHandlerMethodArgumentResolver;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@SpringBootApplication
@MapperScan("com.owc.dao")
@EnableCaching
@EnableTransactionManagement
@EnableSwagger2
@EnableSpringDataWebSupport
@Slf4j
public class OwcApplication {

    private final OwcConfig owcConfig;
    private final OssConfig ossConfig;

    public OwcApplication(OwcConfig owcConfig,OssConfig ossConfig) {
        this.owcConfig = owcConfig;
        this.ossConfig = ossConfig;
    }

    public static void main(String[] args) {
        SpringApplication.run(OwcApplication.class, args);
    }

    @Bean
    public DataLoader dataLoader() {
        return new DataLoader();
    }

    @Order
    static class DataLoader implements CommandLineRunner {

        @Override
        public void run(String... args) {
            long start = System.currentTimeMillis();
            //Init redis component
            RedisUtil.initRedis();
            OssUtils.getInstance();
            log.info("System before component init successful. OverTime:[{}]",(System.currentTimeMillis() - start));
        }
    }
}
